<template>
  <div class="app-container">
    <el-form ref="complaint" :rules="rules" :model="complaint" label-width="150px">
      <el-form-item label="编号" prop="code">
        <el-input v-model="complaint.code" />
      </el-form-item>
      <el-form-item label="主诉内容" prop="content">
        <el-input v-model="complaint.content" />
      </el-form-item>
    </el-form>
    <div class="op-container">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleCreate">保存</el-button>
    </div>
  </div>
</template>

<script>
import { createComplaint } from "@/api/complaint"
import { MessageBox } from "element-ui"

export default {
  name: "ComplaintCreate",
  data() {
    return {
      complaint: {
        code: '',
        content: ''
      },
      rules: {
        content: [{ required: true, message: '主诉内容不能为空', trigger: 'blur' }]
      },
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {},
    handleCancel() {
      this.$router.push({ path: '/complaint/list' })
    },
    handleCreate() {
      createComplaint(this.complaint).then(response => {
        this.$notify.success({
          title: '成功',
          message: '创建成功'
        })
        this.$router.push({ path: '/complaint/list' })
      }).catch(response => {
        MessageBox.alert('业务错误：' + response.data.errmsg, '警告', {
          confirmButtonText: '确定',
          type: 'error'
        })
      })
    }
  }
}
</script>

<style scoped>
.op-container {
  display: flex;
  justify-content: center;
}
</style>
